/**
 * 参数类型检查
 * @param date 需要检查的数据
 * @param type 正确的类型
 */
export function typeCheck(data: any, type: string) {
  let isValid = true
  switch (type) {
    case 'array':
      isValid = Array.isArray(data)
      break
    case 'undefined':
      isValid = data === undefined
      break
    case 'url':
      try {
        if (!data.startsWith('https:') && !data.startsWith('http:')) return false
        new URL(data)
        isValid = true
      } catch {
        isValid = false
      }
      break
    default:
      isValid = typeof data === type
  }
  return isValid
}

// 判断字符是否是数字字符
export function isStringNumber(value: any): boolean {
  if (!typeCheck(value, 'string')) return false
  return !Number.isNaN(Number(value))
}
